﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class OrderLogistics : SkinnedEditControl<LogisticsInfo>
    {
        private LogisticsCompanyDropDownList logisticsCompany;
        private TextBox tbxTrackingNumber;
        private TextBox tbxSendDates;
        private TextBox tbxRemark;


        protected override void InitSkin(Control skin)
        {
            logisticsCompany = (LogisticsCompanyDropDownList)skin.FindControl("logisticsCompany");
            tbxTrackingNumber = (TextBox)skin.FindControl("tbxTrackingNumber");
            tbxSendDates = (TextBox)skin.FindControl("tbxSendDates");
            tbxRemark = (TextBox)skin.FindControl("tbxRemark");
        }

        protected override string DefaultSkinFilename
        {
            get { return "Order/OrderLogistics.ascx"; }
        }

        protected override LogisticsInfo ModelByFrom
        {
            get
            {
                LogisticsInfo info = new LogisticsInfo();
                info.Name = logisticsCompany.SelectedItem.Text;
                info.LtsType = logisticsCompany.SelectedValue;
                info.SendDates = Convert.ToDateTime(tbxSendDates.Text.Trim());
                info.TrackingNumber = tbxTrackingNumber.Text.Trim();
                info.Remark = tbxRemark.Text.Trim();

                info.OrderId = Id;
                info.DateCreated = DateTime.Now;

                return info;
            }
            set
            {
                if (value == null)
                    return;

                logisticsCompany.SelectedValue = value.LtsType;
                tbxSendDates.Text = value.SendDates.ToString();
                tbxTrackingNumber.Text = value.TrackingNumber;
                tbxRemark.Text = value.Remark;
            }
        }

        protected override void Add(LogisticsInfo model)
        {
            throw new NotImplementedException();
        }

        protected override void Update(LogisticsInfo model)
        {
            Orders.UpdateLogiscits(model);
        }

        protected override LogisticsInfo FindById(int id)
        {
            OrderInfo entity = Orders.GetOrder(id);

            return entity.Logistics;
        }
    }
}
